package com.javasea.patterns.strategy.base;

import com.javasea.patterns.strategy.base.strategy.HighPriceRank;
import com.javasea.patterns.strategy.base.strategy.HighRiseRank;
import com.javasea.patterns.strategy.base.strategy.LowPriceRank;

import java.util.List;

public class Demo {

    /**
     * dataService.getSource() 提供原始的股票数据
     */
    /**
     * 前端传入榜单类型, 返回排序完的榜单
     *
     * @param rankType 榜单类型
     * @return 榜单数据
     */
    public List<Stock> getRank(String rankType) {
        // 创建上下文
        Context context = new Context();
        // 这里选择策略
        switch (rankType) {
            case "HighPrice":
                context.setStrategy(new HighPriceRank());
                break;
            case "LowPrice":
                context.setStrategy(new LowPriceRank());
                break;
            case "HighRise":
                context.setStrategy(new HighRiseRank());
                break;
            default:
                throw new IllegalArgumentException("rankType not found");
        }
        List<Stock> highRise = List.of(new Stock(), new Stock());
        // 然后执行策略
        return context.getRank(highRise);
    }
}
